﻿/**
 *	(C) 2014 Yuanjj
 *
 *	define thread base class
 *
 *	histroy
 * 		2014-08-07	yuanjj	- create the file
 */

#ifndef _BASE_THREAD_H_
#define _BASE_THREAD_H_

#include "typedef.h"
#include "ui/bridge/html_bridge.h"
#include <QThread>

class vbase_thread : public QThread
{
    Q_OBJECT

public:
    vbase_thread();
    ~vbase_thread();

protected:
    pem_bool_t		m_stop;			// stop flag, flase:running, true:stop

public:
    /**
     *	start thread
     */
    pem_error_t		start_thread();

    /**
     *	stop thread
     */
    pem_void_t		stop_thread();
};

class base_thread : public vbase_thread
{
    Q_OBJECT

public:
    base_thread();
    ~base_thread();

protected:
    pem_u8_t		m_tunnel;		// tunnel type
    pem_u8_t		m_main;			// protocal main

signals:
    /**
     *	signal for calling js function
     */
    void 	call_js( QString );

protected:
    /**
     *	thread fun for dealing protocal
     */
    virtual pem_void_t		run();

protected:
    /**
     *	recv a protocal from db tunnel
     */
    virtual	pem_error_t		recv_protocal( pem_s8_t* pdata, pem_u32_t size, pem_u32_t& rcvsize );

    /**
     *	deal protocal recv from the db tunnel
     */
    virtual pem_error_t		deal_protocal( pem_s8_t* pdata, pem_u32_t size );
};

#endif // _BASE_THREAD_H_
